;;; init-ivy.el --- ivy

;;; Commentary:

;;; Code:

(use-package counsel
  :diminish ivy-mode counsel-mode
  :bind (("C-s"   . swiper-isearch)
         ("C-r"   . swiper-isearch-backward)
         ("s-f"   . swiper)
         ("C-S-s" . swiper-all)

	 ("C-c c g" . counsel-grep)
	 ("C-c c h" . counsel-command-history)
	 ("C-c c i" . counsel-git)
	 ("C-c c l" . counsel-git-log)
	 ("C-c c r" . counsel-rg)
	 ("C-c t z" . counsel-fzf))
  :hook ((after-init . ivy-mode)
         (ivy-mode . counsel-mode))
  :init
  (setq enable-recursive-minibuffers t) ;; Allow commands in minibuffers

  (setq ivy-height 12
	ivy-use-selectable-prompt t
	ivy-use-virtual-buffers t
	ivy-fixed-height-minibuffer t
	ivy-count-format "(%d/%d)"
	ivy-on-del-error-function #'ignore
	ivy-initial-inputs-alist nil)

  (setq swiper-action-recenter t)

  (setq counsel-find-file-at-point t
	counsel-preselect-current-file t
	counsel-yank-pop-separator "\n------------\n")
  (add-hook 'counsel-grep-post-action-hook #'recenter)

  ;; use the faster search tools
  (when (executable-find "rg")
    (setq counsel-grep-base-command "rg -S -no-heading --line-number --color never %s %s"))

  )

(use-package ivy-rich
  :hook ((counsel-project-mode . ivy-rich-mode)
	 (ivy-rich-mode . ivy-rich-project-root-cache-mode)
	 (ivy-rich-mode . (lambda ()
			    "Use abbreviate in `ivy-rich-mode'`"
			    (setq ivy-virtual-abbreviate
				  (or (and ivy-rich-mode 'abbreviate) 'name)))))
  :init
  (setq ivy-rich-parse-remote-buffer nil))

(use-package ivy-posframe
  :custom-face
  (ivy-posframe ((t (:inherit tooltip))))
  (ivy-posframe-border ((t (:background ,(face-foreground 'font-lock-comment-face nil t)))))
  :hook (ivy-mode . ivy-posframe-mode)
  :init
  (setq ivy-height 15
	ivy-posframe-border-width 3
	ivy-posframe-parameters '((left-fringe . 8)
				  (right-fringe . 8))))

(provide 'init-ivy)
;;; init-ivy.el ends here
